<?php
declare (strict_types = 1);

namespace app\api\middleware;

use app\api\exception\ApiException;
use app\common\lib\Identity;

class LoginAuth
{
    /**
     * 处理请求
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
	    if(!$request->header('access_token')){
			throw new ApiException('缺少参数access_token');
	    }

		if(!Identity::validateAccessToken($request->param('appid'),$request->header('access_token'))){
			throw new ApiException('access_token或者appid错误，请验证');
		}
		return $next($request);
    }
}
